﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.IO;
using System.Threading;


namespace ATM.DBlayer
{
    public class CurrencyTrasDB
    {
       // public int num, numm, result, addB;
       // public int addBalan , checkWich;
        public int balance, sale , buy;
 
      /* public void getBalance(string accountNum)
       {
           try
           {
               string myconnection = "datasource=localhost;port=3306;username=root;password=1234";
               MySqlConnection myconn = new MySqlConnection(myconnection);
               MySqlCommand SelectCommand = new MySqlCommand("SELECT * FROM atm.atm_customers where Account_Number='" + accountNum + "';", myconn);
               MySqlDataReader myreader;

               myconn.Open();
               myreader = SelectCommand.ExecuteReader();
               while (myreader.Read())
               {
                   balance = int.Parse((myreader["balance"].ToString()));
               }



               myconn.Close();
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       
       }*/


       public void balanceChanges(string acc, int BALAN)
       {
           string myconnection2 = "datasource=localhost;port=3306;username=root;password=1234";
           MySqlConnection myconn2 = new MySqlConnection(myconnection2);

           MySqlCommand SelectCommand2 = new MySqlCommand("update atm.atm_customers set balance='" + BALAN + "' where Account_Number='" + acc + "';", myconn2);

           MySqlDataReader myreader2;

           myconn2.Open();
           myreader2 = SelectCommand2.ExecuteReader();


           myconn2.Close();
       
       }



        public void calculate_trasform_to_bound(string name)
        {
            try
            {
                string myconnection = "datasource=localhost;port=3306;username=root;password=1234";
                MySqlConnection myconn = new MySqlConnection(myconnection);
                MySqlCommand SelectCommand = new MySqlCommand("SELECT * FROM atm.currency_transfer where Currency_Name='" + name + "';", myconn);
                MySqlDataReader myreader;


                myconn.Open();
                myreader = SelectCommand.ExecuteReader();
                while (myreader.Read())
                {
                    buy = int.Parse((myreader["Buy"].ToString()));
                }
                myconn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        
        }

        public void calculate_trasform_from_bound(string CName)
        {
            try
            {
                string myconnection = "datasource=localhost;port=3306;username=root;password=1234";
                MySqlConnection myconn = new MySqlConnection(myconnection);
                MySqlCommand SelectCommand = new MySqlCommand("SELECT * FROM atm.currency_transfer where Currency_Name='" + CName + "';", myconn);
                MySqlDataReader myreader;


                myconn.Open();
                myreader = SelectCommand.ExecuteReader();
                while (myreader.Read())
                {
                    sale = int.Parse((myreader["Sale"].ToString()));
                }
                myconn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        
        }

    }
}
